package com.ksjourney;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;

import mars.game.core.MarsRuntime;
import mars.game.core.MarsView;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.MotionEvent;

public class KSJourney extends Activity // implements View.OnClickListener
{
	
	/**
	 * Required method from parent class
	 * 
	 * @param savedInstanceState
	 *            - The previous instance of this app
	 */
	public void onCreate(Bundle savedInstanceState)
	{

		super.onCreate(savedInstanceState);
		MarsView marsView = new MarsView(this);
		GameUI gameUI = new GameUI();
		
		MarsRuntime.getRuntime().changeScreen(gameUI, 0, null);
		
		setContentView(marsView);
	}
	
	@Override
	public boolean onTouchEvent(MotionEvent event)
	{

		MarsRuntime.getRuntime().onTouchEvent(event);
		
		// int iAction = event.getAction();
		// float x = event.getX();
		// float y = event.getY();
		// if (iAction == MotionEvent.ACTION_CANCEL)
		// {
		// System.out.println("Activity ACTION_CANCEL == " + x + ";" + y);
		// }
		// else if (iAction == MotionEvent.ACTION_DOWN)
		// {
		// System.out.println("Activity ACTION_DOWN == " + x + ";" + y);
		// }
		// else if (iAction == MotionEvent.ACTION_MOVE)
		// {
		// System.out.println("Activity ACTION_MOVE == " + x + ";" + y);
		// }
		// else if (iAction == MotionEvent.ACTION_OUTSIDE)
		// {
		// System.out.println("Activity ACTION_OUTSIDE == " + x + ";" + y);
		// }
		// else if (iAction == MotionEvent.ACTION_UP)
		// {
		// System.out.println("Activity ACTION_UP == " + x + ";" + y);
		// }
		
		return super.onTouchEvent(event);
	}
	
	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event)
	{

		MarsRuntime.getRuntime().onKeyDown(keyCode, event);
		return true;
		// return super.onKeyDown(keyCode, event);
	}
	
	@Override
	public boolean onKeyUp(int keyCode, KeyEvent event)
	{

		MarsRuntime.getRuntime().onKeyUp(keyCode, event);
		// return super.onKeyUp(keyCode, event);
		return true;
	}
	
	public FileOutputStream openFile()
	{
		try
		{
			return this.openFileOutput("game.cfg",Context.MODE_WORLD_READABLE);
		}
		catch (FileNotFoundException e)
		{
			// TODO Auto-generated catch block
			return null;
		}
	}
	
}
